Change the console handling, to remove the loop and timeout if a console fails
authoremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Sun, 27 Nov 2005 01:06:20 +0000 (01:06 +0000)
committeremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Sun, 27 Nov 2005 01:06:20 +0000 (01:06 +0000)
to respond first time.  For restored and unpaused domains there is no need for
the console to output data, so we cannot use this as a way to detect the
liveness of a console.  Instead, a command must always be sent to the console,
which means that this failure can only be detected once the constructor of the
Console class has returned successfully.  The __chewall loop still remains, in
order to detect runaway consoles and to clear out previous data from the
console before executing commands, but we no longer treat failure of that
method to read data as a failure of the console itself.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/xm-test/lib/XmTestLib/Console.py
tools/xm-test/tests/restore/01_restore_basic_pos.py
tools/xm-test/tests/unpause/01_unpause_basic_pos.py

index f502adc8592fe9b57d41b045f80f46fb043a1998..33455ef047fa502f41deaa43165893f400c319d1 100755 (executable)
@@ -66,37 +66,25 @@ class XmConsole:
         self.historySaveCmds  = historySaveCmds
         self.debugMe          = False
         self.limit            = None
-        self.delay            = 2
 
         consoleCmd = ["/usr/sbin/xm", "xm", "console", domain]
 
-        start = time.time()
-
-        while (time.time() - start) < self.TIMEOUT:
-            if verbose:
-                print "Console executing: %s" % str(consoleCmd)
+        if verbose:
+            print "Console executing: %s" % str(consoleCmd)
 
-            pid, fd = pty.fork()
+        pid, fd = pty.fork()
 
-            if pid == 0:
-                os.execvp("/usr/sbin/xm", consoleCmd[1:])
+        if pid == 0:
+            os.execvp("/usr/sbin/xm", consoleCmd[1:])
 
-            self.consolePid = pid
-            self.consoleFd  = fd
+        self.consolePid = pid
+        self.consoleFd  = fd
 
-            tty.setraw(self.consoleFd, termios.TCSANOW)
-            
-            bytes = self.__chewall(self.consoleFd)
+        tty.setraw(self.consoleFd, termios.TCSANOW)
 
-            if bytes > 0:
-                return
+        self.__chewall(self.consoleFd)
 
-            if verbose:
-                print "Console didn't attach, waiting %i sec..." % self.delay
-            time.sleep(self.delay)
 
-        raise ConsoleError("Console didn't respond after %i secs" % self.TIMEOUT)
-    
     def __addToHistory(self, line):
         self.historyBuffer.append(line)
         self.historyLines += 1
@@ -145,8 +133,8 @@ class XmConsole:
                     if self.debugMe:
                         sys.stdout.write(foo)
                     bytes += 1
-                except:
-                    timeout += 1
+                except Exception, exn:
+                    raise ConsoleError(str(exn))
 
             else:
                 timeout += 1
@@ -174,7 +162,7 @@ class XmConsole:
 
         os.write(self.consoleFd, "%s\n" % command)
 
-        while 1==1:
+        while True:
             i, o, e = select.select([self.consoleFd], [], [], self.TIMEOUT)
 
             if self.consoleFd in i:
@@ -183,9 +171,10 @@ class XmConsole:
                     if self.debugMe:
                         sys.stdout.write(str)
                     bytes += 1
-                except:
-                    raise ConsoleError("Failed to read from console (fd=%i)"
-                                       % self.consoleFd)
+                except Exception, exn:
+                    raise ConsoleError(
+                        "Failed to read from console (fd=%i): %s" %
+                        (self.consoleFd, exn))
             else:
                 raise ConsoleError("Timed out waiting for console")
 
index 5241365d49cd2fa53471646e961cd3f193bae7dc..df9c8018dd8ba463a697fdc2f4732ddab61f279c 100644 (file)
@@ -63,6 +63,9 @@ if not isDomainRunning(domain.getName()):
 # Make sure it's alive
 try:
     newConsole = XmConsole(domain.getName())
+    run = newConsole.runCmd("ls")
+    if run["return"] != 0:
+        FAIL("Unable to read from restored domain")
 except ConsoleError, e:
     FAIL("Restored domain is dead (%s)" % str(e))
 
index 73a4a805c726d90db4b2dfef26681769c9b52ba4..d459c6abd116610007f39075137c53ea82f0c87f 100644 (file)
@@ -70,9 +70,6 @@ if status != 0:
 # Are we still alive after all that?
 try:
     console = XmConsole(domain.getName(), historySaveCmds=True)
-except ConsoleError, e:
-    pass
-try:
     run = console.runCmd("ls")
 except ConsoleError, e:
     FAIL(str(e))